function _formatDuration(number) {
	if (!isNaN(number)) {
		var minutes = parseInt(number / 60);
		var seconds = parseInt(number % 60);
		seconds < 10 && (seconds = "0" + seconds);
		return minutes + ":" + seconds;
	}
	return "0:00";
}

function _delParam(url, name) {
	var urlArr = url.split('?');
	if (urlArr.length > 1 && urlArr[1].indexOf(name) > -1) {
		var query = urlArr[1];
		var obj = {}
		var arr = query.split("&");
		for (var i = 0; i < arr.length; i++) {
			arr[i] = arr[i].split("=");
			obj[arr[i][0]] = arr[i][1];
		};
		delete obj[name];
		var urlte = urlArr[0] + '?' + JSON.stringify(obj).replace(/[\"\{\}]/g, "").replace(/\:/g, "=").replace(/\,/g, "&");
		return urlte;
	} else {
		return url;
	}
}

function _existParm(url, name) {
	var urlArr = url.split('?');
	if (urlArr.length > 1) {
		if (urlArr[1].indexOf(name) < 0) {
			return false
		} else {
			return true
		}
	} else {
		return false;
	}
}
// #ifdef MP-WEIXIN
function _getParm(options, name) {
	var _value = '';
	if (options) {
		for (let [key, value] of Object.entries(options)) {
			if (key == name) {
				_value = value;
				break;
			}
		}
	}
	return decodeURIComponent(_value);
}
// #endif
// #ifdef H5
function _getParm(url, name) {
	var urlArr = url.split('?');
	if (urlArr.length > 1) {
		var query = urlArr[1];
		var vars = query.split("&");
		for (var i = 0; i < vars.length; i++) {
			var pair = vars[i].split("=");
			if (pair[0] == name) {
				return  decodeURIComponent(pair[1]);
			}
		}
	}
	return ''
}
// #endif
function _addParm(url, name, value) {
	var urlArr = url.split('?');
	if (urlArr.length > 1) {
		if (urlArr[1].indexOf(name) < 0) {
			url = url + '&' + name + '=' + value;
		}
	} else {
		url = url + '?' + name + '=' + value;
	}
	return url;
}


function _delEmptyParam(url) {
	var urlArr = url.split('?');
	if (urlArr.length > 1 && !urlArr[1]) {
		return urlArr[0]
	} else {
		return url;
	}
}

export const formatDuration = _formatDuration;
export const delParam = _delParam;
export const delEmptyParam = _delEmptyParam;
export const addParm = _addParm;
export const existParm = _existParm;
export const getParm = _getParm;
